package com.sk.cardeal.adapter;

import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sk.cardeal.R;
import com.sk.cardeal.base.BaseFragment;
import com.sk.cardeal.entity.Custom;

import java.util.List;

/**
 * Created by sk on 2018/1/20.
 */

public class CustomAdapter extends BaseMultiItemQuickAdapter<Custom, BaseViewHolder> {

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public CustomAdapter(List<Custom> data) {
        super(data);
        addItemType(-1, R.layout.item_search_custom);
        addItemType(0, R.layout.item_temporary_vip);
        addItemType(1, R.layout.item_vip);
        addItemType(2, R.layout.item_vip);
    }

    @Override
    protected void convert(BaseViewHolder helper, Custom item) {

        switch (item.getItemType()) {
            case -1:
                helper.setText(R.id.car_num, item.getPlateNumber() == null || item.getPlateNumber().length() == 0 ? "暂无信息" : item.getPlateNumber())
                        .setText(R.id.tv_name, item.getPersonName() == null || item.getPersonName().length() == 0 ? "暂无信息" : item.getPersonName())
                        .setText(R.id.tv_phone, item.getTelephone());
                break;
            case 0:
                helper.setText(R.id.car_num, item.getPlateNumber() == null || item.getPlateNumber().length() == 0 ? "暂无记录" : item.getPlateNumber())
                        .setText(R.id.in_time, "最近一次来访：" + (item.getLastArrivalDate() == null || item.getLastArrivalDate().length() == 0 ? "暂无记录" : item.getLastArrivalDate()));
                break;
            case 1:
                helper.setText(R.id.car_num, item.getPlateNumber() == null || item.getPlateNumber().length() == 0 ? "暂无记录" : item.getPlateNumber())
                        .setText(R.id.in_time, "最近一次来访：" + (item.getLastArrivalDate() == null || item.getLastArrivalDate().length() == 0 ? "暂无记录" : item.getLastArrivalDate()))
                        .setText(R.id.car_type, item.getText())
                        .setText(R.id.tv_name, item.getPersonName() == null || item.getPersonName().length() == 0 ? "暂无信息" : item.getPersonName());
                break;
            case 2:
                helper.setText(R.id.car_num, item.getPlateNumber() == null || item.getPlateNumber().length() == 0 ? "暂无记录" : item.getPlateNumber())
                        .setText(R.id.in_time, "最近一次来访：" + (item.getLastArrivalDate() == null || item.getLastArrivalDate().length() == 0 ? "暂无记录" : item.getLastArrivalDate()))
                        .setText(R.id.car_type, item.getText())
                        .setText(R.id.tv_name, item.getPersonName() == null || item.getPersonName().length() == 0 ? "暂无信息" : item.getPersonName());
                break;
        }

    }
}
